/************************************************
 * Copyright (c) 2007 ~ 2009, 
 * All rights reserved.
 * Version   : 1.0
 * Author    : lengsh@alibaba-inc.com 
 * Date      : 2007.12.6
 ***********************************************/

#ifndef _GONGFU_PANDA_NETWORK_H_
#define _GONGFU_PANDA_NETWORK_H_

#include <memory>
#include <vector>
#include <string>
#include <map>
#include "Defines.h"

using namespace std;

class Network 
{
	protected:
                conn *listen_conn;
                conn **freeconns;
                int freetotal;
                int freecurr;

	public:
		Network(){  
			freeconns = NULL;
			freetotal = 200;
			freecurr = 0;
		}
		virtual ~Network(){}
	public:
//		int transmit(conn *c);
		void maximize_sndbuf(int);
		int new_socket(struct addrinfo *ai);
		int new_socket_unix();
		int server_socket_unix(const char*, int);
		int server_socket(const int port);

//		int try_read_command(conn *c);
		int try_read_network(conn *c);
//		int try_read_udp(conn *c);

		bool conn_init(void);
		void conn_free(conn *c);
		void conn_close(conn *c);
		void conn_cleanup(conn *c);
		conn * conn_new(const int sfd, const int init_state, const int event_flags, const int read_buffer_size, const bool is_udp, struct event_base *base) ;
		void conn_listen_accept( bool do_accept);
		bool do_conn_add_to_freelist(conn *c) ;
		conn *do_conn_from_freelist() ;
                int  write_block(conn *c); //,const char *buf, unsigned blen);

};
#endif //_GONGFU_PANDA_RESOURCE_UTILS_H_

